home *** CD-ROM | disk | FTP | other *** search
- Path: rain.fr!world-net!usenet
- From: Frederic LACHASSE <lachass@worldnet.fr>
- Newsgroups: comp.lang.c++
- Subject: Re: ostrstreams
- Date: Tue, 16 Jan 1996 19:34:25 +0000
- Organization: World-Net information exchange, Internet provider.
- Message-ID: <VA.0000000d.00290fd5@fred>
- References: <4de6g3$e6u@saturn.ball.com>
- Reply-To: lachass@worldnet.fr
- NNTP-Posting-Host: client75.sct.fr
- X-Newsreader: Virtual Access by Ashmount Research Ltd, http://www.ashmount.com
-
-
- jsaler@ball.com (Jeff Saler) wrote:
- > I am using a function which requires an ostream reference as one of
- > its parameters. After each call, I extract a string using the str()
- > function. I would like to have the next string that the function
- > inserts into the ostream to overwrite the previous one instead of
- > being appended. I tried calling flush(), but this had
- > no effect.
-
- Use seekp(0), but don't forget to unfreeze the strstreambuf before as
- str() freezes it.
-
- example:
-
- ostrstream os;
-
- // output operation:
- os << ...;
-
- // generally, I put a null byte at the end of the buffer
- os << ends;
-
- // getting a pointer to the buffer
- char *buf = os.str();
-
- // use buf
- ...
-
- // str() freezes the strstreambuf, so that the pointer returned
- // won't change, so we must unfreeze it
- // note: buf should not be used after that
- os.rdbuf()->freeze(0);
-
- // then reset the stream
- os.seekp(0);
-
- Frederic LACHASSE (ECP 86)
- CompuServe: 100530,2005
- Internet: lachass@worldnet.fr
-
-